package com.yuan.algorithms.arithmetic_1;

import java.util.Scanner;


public class 递归_错排算法 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext())
			System.out.println(errorSort(sc.nextInt()));
	}

	/**
	 * @param n
	 * @return
	 */
	public static int errorSort(int n) {
		if (n == 1) {
			return 0;
		} else if (n == 2) {
			return 1;
		} else {
			return (n - 1) * (errorSort(n - 1) + errorSort(n - 2));
		}
	}

}
